#ifndef DATAMONITOR_H
#define DATAMONITOR_H

#include <QObject>

#include <QGeoCoordinate>
#include <QGeoSatelliteInfo>
#include <QGeoSatelliteInfoSource>
#include <QGeoServiceProvider>
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
#include <QCompass>
#include <QCompassReading>
#include <QTimer>

/*
QTM_BEGIN_NAMESPACE
class QGeoPositionInfo;
class QGeoPositionInfoSource;
class QCompass;
class QCompassReading;
QTM_END_NAMESPACE
*/

QT_BEGIN_NAMESPACE
class QTimer;
QT_END_NAMESPACE

QTM_USE_NAMESPACE

class DataMonitor : public QObject
{
    Q_OBJECT

private:
    QGeoServiceProvider     * serviceProvider;
    QGeoPositionInfoSource  * possource;

    QCompass                * compass;
    QCompassReading         * reading;
    QGeoSatelliteInfoSource * satsource;
    QList<QGeoSatelliteInfo>  satsinuse;
    QList<QGeoSatelliteInfo>  satsinview;
    QGeoPositionInfo          posinfo;
    QTimer                    timer;

    void initialize();

signals:
    void headingChanged();
    void timeChanged();
    void positionChanged();
    void positionChanged(double, double);
    void positionChanged(const QGeoCoordinate &);
    void speedChanged();
    void altitudeChanged();
    void satellitesChanged();

public:
    // Compass
    Q_INVOKABLE int heading();
    Q_INVOKABLE int bearing();

    // Statusbar
    Q_INVOKABLE QString position();

    // Position
    Q_INVOKABLE double latitude();
    Q_INVOKABLE double longitude();
    Q_INVOKABLE double altitude();

    /*
    // Clock
    Q_INVOKABLE QDateTime time();
    Q_INVOKABLE QDateTime triptime();
    Q_INVOKABLE QDateTime eta();

    // Speedometer
    Q_INVOKABLE double speed();
    Q_INVOKABLE double distance();

    // Level indicators
    Q_INVOKABLE int compassLevel();
    Q_INVOKABLE int horizontalLevel();
    Q_INVOKABLE int verticalLevel();
    */

    // Constructor
    DataMonitor(QObject * parent = 0);
    ~DataMonitor();

private slots:
    void timerFired();
    void readingChanged();
    void OnPositionUpdate(const QGeoPositionInfo& info);
    void UpdateSatsInUse(const QList<QGeoSatelliteInfo>& inuse);
    void UpdateSatsInView(const QList<QGeoSatelliteInfo>& inview);
};

#endif // DATAMONITOR_H
